/*************************************************************************
	> File Name: clock_getcpu-time.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sat 05 Jul 2014 03:14:33 PM CST
 ************************************************************************/

#include"head.h"
#include <time.h>
#define _POSIX_C_SOURCE 199309
int main(int argc,char *argv[])
{
    pid_t pid;
    struct timespec tp;
    pid=atoi(argv[1]);

    clockid_t id; // this id's content is the return of the function below\
    so no need to declare id to CLOCK_REALTIME or something

    if(clock_getcpuclockid(pid,&id)!=0)
    {
        perror("getcpuclockid:");
        _exit(errno);
    }

    if(clock_gettime(id,&tp)==-1) // id is the return of above function
    {
        perror("gettime");
        _exit(errno);
    }

    printf("tv_sec:%ld\t tv_nsec:%ld\n",tp.tv_sec,tp.tv_nsec);
}
